home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / radiance / simplerd.lha / simplerad / FinalFTP / Light / struct.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-21  |  11.3 KB  |  277 lines

  1. /**********************************************************************/
  2. /* struct.h :                                                         */
  3. /*                                                                    */
  4. /* Final structures for radiosity / ray tracing program               */
  5. /*                                                                    */
  6. /* Copyright (C) 1992, Bernard Kwok                                   */
  7. /* All rights reserved.                                               */
  8. /* Revision 1.0                                                       */
  9. /* May, 1992                                                          */
  10. /**********************************************************************/
  11. #ifndef STRUCT_H
  12. #define STRUCT_H 
  13.  
  14. /**********************************************************************/
  15. /* Types for textures and surface, and image attributes               */
  16. /* Output currently restricted to 3 colour RGB                        */
  17. /**********************************************************************/
  18. #define MAX_SPECTRA_SAMPLES 3
  19. typedef struct { double samples[MAX_SPECTRA_SAMPLES]; } Spectra;
  20. typedef struct { unsigned char r,g,b,a; } ColourChar;
  21. typedef struct { double r, g, b, a; } Colour;
  22.  
  23. /**********************************************************************/
  24. /* Object types                                                       */
  25. /**********************************************************************/
  26. /* light classifications : note classification is based on given      */
  27. /* tolerances (not used)                                              */
  28. #define LIGHT_DIR    1           /* Directional light (area)       */
  29. #define LIGHT_NONDIR    2           /* Non-directional light (area)   */
  30. #define LIGHT_PT    3           /* Point light source             */
  31.  
  32. /* types of primitive objects */
  33. #define CONE        1          /* A cone                          */
  34. #define CONE_ID         "cone"
  35. #define CUBE        2          /* A cube                          */
  36. #define CUBE_ID         "cube"
  37. #define CYLINDER    3          /* A cylinder                      */
  38. #define CYLINDER_ID     "cylinder"
  39. #define DISK        4          /* A disk                          */
  40. #define DISK_ID         "disk"
  41. #define SPHERE        5          /* A sphere                        */
  42. #define SPHERE_ID       "sphere"
  43. #define MESH            6          /* A polygonal mesh                */
  44. #define MESH_ID         "mesh"
  45. #define PATCH        7          /* A 4 sided polygon in a mesh     */
  46. #define PATCH_ID        "patch"
  47. #define TRIANGLE    8          /* A 3 sided polygon in a mesh     */
  48. #define TRI_ID         "triangle"
  49.  
  50. #define LIGHT_SRC    1          /* A primitive is a light source   */
  51. #define NONLIGHT_SRC    2          /* A primitive is not light source */
  52.  
  53. /* types of nodes in scene */
  54. #define OBJECT        1          /* An object                       */
  55. #define SURFACE        2          /* A surface property              */
  56. #define TEXTURE        3          /* A texture map                   */
  57. #define ALL            4
  58.  
  59. #define MAX_PATCH_VTX   4          /* Maximum vertices per patch      */
  60. #define MAX_TRI_VTX     3          /* Number of vertices per triangle */
  61. #define MAX_PATCH_CHILDREN 4       /* Maximum subpatches per patch    */
  62.  
  63. /* Polygon list */
  64. typedef struct PolyListType {
  65.   struct PolyType *patch;
  66.   struct PolyListType *next;
  67. } PolyList;
  68.  
  69. typedef struct PolyListHeadType {
  70.   PolyList *front, *back;
  71.   int num_polys;
  72. } PolyListHead;
  73.  
  74. /* Vertex */
  75. typedef struct VertexType {
  76.   int id;
  77.   char *name;
  78.   Vector pos;            /* vertex coordinates                       */
  79.   PolyList* polylist;    /* List of polygons vertex belongs to       */
  80.   PolyListHead polyhead; /* Info on polygon list                     */
  81. } Vertex;
  82.  
  83. /* U, V and possible W planes of quad or triangle */
  84. typedef struct PolyUVW {
  85.   Vector Nu, Nv, Nw;    /* normals for above planes                  */
  86.   double Lu, Lv, Lw;    /* length of edges u,v,w                     */
  87.   double du, dv, dw;
  88. } polyUVW;
  89.  
  90. /* Patches / elements  */
  91. typedef struct PolyType { /* Assume vertices of a patch are on the 
  92.                  same plane */
  93.   int id;               /* Id */
  94.   char *name;
  95.   int class;            /* classification (patch or element)         */
  96.   Vertex *vert[4];      /* vertices                                  */
  97.   Vector normal[4];    /* normals                                   */
  98.   int changingNormal;    /* if TRUE, then normal changes within patch */
  99.   double area;          /* area                                      */
  100.   polyUVW *uvw;         /* u,v,w planes along edges of polygon       */
  101.   int numVert;          /* Number of vertices in patch               */
  102.   struct PolyType *child[4]; /* Subpatches of this patch / element   */
  103.   double d;        /* d of plane on which patch / element 
  104.                resides */
  105.   int level;            /* subdivision level                         */
  106.   struct MeshType *Mfather; /* Mesh patch belongs to                 */
  107.   struct PolyType *next; /* Next patch in mesh (if a patch)          */
  108.   struct PolyType *Pfather; /* Larger patch or element, this element
  109.                    belongs to */
  110.   PolyList* Links;      /* Form-factor linkages                      */
  111.   PolyListHead polyhead; /* Info on polygon list                     */
  112.   Spectra unshot_B;     /* Unshot radiosity                          */
  113.   Spectra B;            /* Total radiosity = emission originally     */
  114.   Spectra               /* Vertex radiosity                          */
  115.     vtx_B[MAX_PATCH_VTX];     
  116.   Spectra               /* Vertex display radiosity                  */
  117.     vtx_dB[MAX_PATCH_VTX];     
  118. } Polygon;
  119.  
  120. /* List of vertices */
  121. typedef struct Vertex_listType {  
  122.   Vertex *vtx;              /* List of all vertices                  */
  123.   struct Vertex_listType *next;
  124. } Vertex_list;
  125.  
  126. /* Mesh */
  127. typedef struct MeshType {
  128.   int id;
  129.   char *name;              /* mesh name                              */
  130.   Polygon *polys;          /* polys in mesh                          */
  131.   int num_polys;           /* number of polys in mesh                */
  132.   struct ObjectType *Ofather;/* Object, mesh belongs to              */
  133.   BoundingBoxType *box;    /* Bounding box for mesh                  */
  134. } Mesh;
  135.  
  136. /**********************************************************************/
  137. /* Physical properties */
  138. /**********************************************************************/
  139. /* Shading type */
  140. typedef struct {
  141.   Spectra Ka;              /* Ambient term (optional)                 */
  142.   Spectra Kd;              /* Diffuse constant                        */
  143.   Spectra Ks;              /* Specular constant                       */
  144.   Spectra p;               /* Reflectance                             */
  145.   Spectra t;               /* Refraction constant                     */
  146.   Spectra n;               /* Index of refraction                     */
  147. } ShadeType;
  148.  
  149. /* Radiating energy */
  150. typedef struct {
  151.   Spectra E;                /* Emittance                              */
  152.   Spectra B;                /* Radiance                               */
  153. } Radiance;
  154.  
  155. /* Transmission type */
  156. typedef struct {
  157.   Spectra trans;           /* Transmission constant                   */
  158.   Spectra Ktrans;          /* Transmissivity                          */
  159.   Spectra blendCol;       
  160. } Transmit;
  161.  
  162. /* Specular type */
  163. typedef struct {
  164.   Spectra n;               /* Currently Phong model                   */
  165.   Spectra metal;           
  166. } Specularity;
  167.  
  168. /* Surface Property */
  169. typedef struct {
  170.   int id;
  171.   char *name;
  172.   ShadeType shade;        /* Reflection, refraction funct. parameters */
  173.   Radiance rad;           /* Radiating energy function parameters     */
  174.   Specularity spec;       /* Reflectance function parameters          */
  175.   Transmit *trans;        /* Transmittance function parameters        */
  176. } SurfaceProp;
  177.  
  178. /* Light specific properties */
  179. typedef struct {
  180.   int id;
  181.   char *name;
  182.   int lightType;          /* Type of light = point/area                */
  183.   double standardDistance;/* distance that light has reasonable intensity */
  184.   Vector shineFrom;      /* position of light                         */
  185.   double dropoff;      /* spotlight factor. if 0, then no spotlight */
  186.   double cutoff;      /* angle at which spot no longer shines      */
  187.   double cosCutoff;      /* not user defined                          */
  188.   Vector shineAt;      /* co-ordinate light is pointed at           */
  189.   Vector shineDir;      /* not user defined                          */
  190.   int maxSamples;
  191.   int usedSamples;
  192. } LightProp;
  193.  
  194. /* Texture map properties */
  195. typedef struct {
  196.   int id;
  197.   char *name;
  198.   int class;              /* Type of texture                          */
  199.   int resolution;         /* Resolution of texture                    */
  200.   ColourChar *map;        /* texture map                              */
  201. } TextureProp;
  202.  
  203. /**********************************************************************/
  204. /* The scene */
  205. /**********************************************************************/
  206. typedef struct SphereInfo {          /* Sphere info */
  207.   Vector orig;
  208.   double r;
  209. } SphereInfo;
  210.  
  211. typedef struct CylInfo {             /* Cylinder info */
  212.   double h;
  213.   double r1, r2;
  214. } CylInfo;
  215.  
  216. typedef struct CubeInfo {            /* Cube info */
  217.   double length;
  218. } CubeInfo;
  219.  
  220. typedef struct ConeInfo {            /* Cone info */
  221.   double h;
  222.   double r1, r2;
  223. } ConeInfo;
  224.  
  225. typedef struct ObjectType {
  226.   int id;
  227.   char *name;
  228.   long rayID;              /* for stats/etc                           */
  229.   Matrix WToM;              /* world space to model space              */
  230.   Matrix MToW;              /* model space to world space              */
  231.   char *primtype;         /* Primitive type (cube, cone, etc)        */
  232.   int primid;             /* Primtive id (CONE, CUBE, etc)           */
  233.   SurfaceProp *surface;   /* Surface properties                      */
  234.   TextureProp *texture;   /* A texture property                      */
  235.   LightProp *light;       /* Light properties                        */
  236.   Mesh *meshes;           /* Associated mesh for primitive           */
  237.   int num_meshes;         /* number of meshes                        */
  238.   char *info;             /* ptr to prim-dependent info,must be cast */
  239.   int (*intersect) ();    /* ptr to intersection routine for prim    */
  240.   BoundingBoxType *box;   /* Bounding box for object                 */
  241.   int in_facingprim;      /* Is this an in facing primitive ?        */
  242. } Objectt;                /* IRIS has Object type already...         */
  243.  
  244. /* The scene */
  245. typedef struct SceneType {
  246.   Objectt *objects;
  247.   TextureProp *textures;
  248.   int num_objects;
  249.   int num_textures;
  250. } Scene;
  251.  
  252. /* Some structure macros: reflectance, patch, object, etc */
  253. #define obj_reflect(obj) ((obj)->surface->shade.p)
  254. #define poly_reflect(ply) ((ply)->Mfather->Ofather->surface->shade.p)
  255. #define poly_emit(ply) ((ply)->Mfather->Ofather->surface->rad.E)
  256. #define poly_patch(p) ((p)->Pfather)
  257. #define poly_object(p) ((p)->Mfather->Ofather)
  258.  
  259. /**********************************************************************/
  260. /* Function prototypes */
  261. /**********************************************************************/
  262. extern void print_PolyList();
  263. extern void print_Polygon();
  264. extern void print_Vertex();
  265. extern void print_VertexList();
  266. extern void print_Colour();
  267. extern void print_Spectra();
  268. extern void print_ShadeType();
  269. extern void print_Radiance();
  270. extern void print_LightProp();
  271. extern void print_TextureMap();
  272. extern void print_Object();
  273. extern void print_Scene();
  274. extern char *ProgName;
  275.  
  276. #endif /* STRUCT_H */
  277.